package scuts.core.macros;

#if macro
import scuts.macro.Convert;
import haxe.macro.Compiler;
import scuts.macro.Check;
import scuts.macro.Extract;
import scuts.macro.Parse;
import scuts.macro.Print;
import scuts.macro.Make;
import haxe.macro.Context;
import haxe.macro.Expr;
using scuts.core.extensions.Options;
using scuts.core.Map;


class MakeTuple {
  /*
   * returns
   *   new TupN(expr0, ... exprN);
   *   
   * usage: 
   *  [1,"hi"].asTuple() => Tup2<Int, String>
   *  [1,"hi", 2.2].asTuple() => Tup3<Int, String, Float>
   */
  public static function asTuple (arr:ExprRequire<Array<Dynamic>>) {
    
    if (!Check.isArrayDecl(arr)) Context.error("Argument arr should be const array", arr.pos);
    var values = Extract.extractArrayDeclValues(arr).value();
    
    var s = "scuts.core.types.Tup" + values.length + ".create(" + values.mapWithIndex(function (e, i) return "$" + i).join(",") + ")";
    var res = Parse.parse(s, values);
    return res;
  }
  
}
#end